const BookTser = require("./booksTest.model");
const { DataTypes } = require('sequelize');
const seq = require('../db/seq');


// 定义 BorrowRecord 模型
const BorrowRecord = seq.define('borrow_records', {
    id: {
        type: DataTypes.INTEGER,
        autoIncrement: true,
        primaryKey: true,
    },
    book_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: BookTser,
            key: 'id',
        },
    },
    is_borrowed: {
        type: DataTypes.STRING,
        allowNull: false,
    },
    borrower_name: {
        type: DataTypes.STRING,
        allowNull: false,
    },
    borrower_idcard: {
        type: DataTypes.STRING,
        allowNull: false,
    },
    borrower_phone: {
        type: DataTypes.STRING,
        allowNull: false,
    },
    borrow_date: {
        type: DataTypes.STRING,
        allowNull: true,
    },
    return_date: {
        type: DataTypes.STRING,
        allowNull: true,
    },
    due_date: {
        type: DataTypes.STRING,
        allowNull: true,
    },
    created_at: {
        type: DataTypes.DATE,
        allowNull: true,
        defaultValue: DataTypes.NOW,
        field: 'created_at'
    },
    updated_at: {
        type: DataTypes.DATE,
        allowNull: true,
        defaultValue: DataTypes.NOW,
        field: 'updated_at',
        onUpdate: DataTypes.NOW
    }
}, {
    tableName: 'borrow_records',
    timestamps: false,
});


// // BookTser.hasMany(BorrowRecord, { foreignKey: 'book_id' });
// BorrowRecord.belongsTo(BookTser, { foreignKey: 'book_id' });
module.exports = BorrowRecord;